package com.example.testapp.activity.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by l on 2016/9/18.
 */
public class DateUtils {



    public static String convertGMTToLoacale(String gmt) {
        String s1 = gmt.substring(0, 10);
        String s2 = gmt.substring(11, 19);
        return s1 + " " + s2;
    }

    /**
     * 将日期格式转化为时间戳(秒数)
     * @param time
     * @return
     */
    public static long getString2Date(String time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date  date = new Date();
        try {
            date = sdf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date.getTime() / 1000;
    }

    /**
     * 得到日期 yyyy-MM-dd
     *
     * @param timeStamp
     *            时间戳
     * @return
     */
    public static String formatDate(long timeStamp) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String  date = sdf.format(timeStamp * 1000);
        return date;
    }
}
